/**
 * 求和
 * @param {Number} a 
 * @param {Number} b 
 * @returns {Number}
 */
function add(a, b) {
    console.log(arguments.length)
    return a + b;
}
document.write(`${add(1, 2)}<br>`);

//函数作为实参
var arr = [12, 34, 28, 16, 50];
document.write(`${arr.sort()}<br>`);
document.write(`${arr.sort(function (a, b) { return b - a; })}<br>`);

//默认参数值
function multiply(a, b = 1) {
    return a * b;
}
document.write(`${multiply(3, 4)}<br>`);
document.write(`${multiply(1)}<br>`);

//剩余参数
(function multiArg(arg, ...args) {
    document.write(arg);
    for (let i = 0; i < args.length; i++) {
        document.write(`{${args[i]}}`);
        
    }
})("剩余参数：", 10, 20, 30, 40);
document.write(`<br>`)

//箭头函数
document.write(`${arr.sort( (a, b) => { return a - b; })}<br>`);
document.write(`${arr.sort( (a, b) => { return b - a; })}<br>`);
document.write(`${arr.sort((a, b) => b - a)}<br>`);